package com.woniu.humanresource.service.impl;

import com.woniu.humanresource.dao.CourseDao;
import com.woniu.humanresource.entity.Course;
import com.woniu.humanresource.entity.PageBean;
import com.woniu.humanresource.service.CourseService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class CourseServiceImpl implements CourseService {

    @Resource
    CourseDao courseDao;

    @Override
    public void insertCourse(Course course) {
        courseDao.insertCourse(course);
    }

    @Override
    public PageBean<Course> selectCourseCondition(Course course, int pageIndex, int pageSize) {
        // 条件查询课程集合
        List<Course> courses = courseDao.selectCourseCondition(course, pageIndex, pageSize);
        // 封装为pagebean对象
        PageBean<Course> pageBean = new PageBean<>();
        pageBean.setBeanList(courses);
        pageBean.setPageIndex(pageIndex);
        pageBean.setPageSize(pageSize);
        pageBean.setBeginEnd();
        pageBean.setTotalRecord(courseDao.selectCourseConditionCount(course));
        return pageBean;
    }

    @Override
    public void updateCourse(Course course) {
        courseDao.updateCourse(course);
    }

    @Override
    public void deleteCourse(int cid) {
        courseDao.deleteCourse(cid);
    }

    @Override
    public List<Course> getAllCourse() {
        List<Course> courses = courseDao.selectAllCourse();
        return courses;
    }
}
